package com.teangtang.fly.repository;

import com.teangtang.fly.entity.Plane;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

public interface PlaneRepository extends JpaRepository<Plane, Long> {
    @Transactional
    @Modifying
    @Query(value = "INSERT INTO plane (name, type) VALUES (:name, :type);SELECT LAST_INSERT_ID();", nativeQuery = true)
    Long savePlane(String name, String type);

    @Transactional
    @Modifying
    @Query(value = "INSERT INTO cabin (name, type, capacity, plane_id) VALUES (:name, :type, :capacity, :planeId)", nativeQuery = true)
    void saveCabin(String name, String type, int capacity, Long planeId);

    @Transactional
    @Modifying
    @Query(value = "DELETE FROM cabin WHERE id = :id", nativeQuery = true)
    void deleteCabinById(Long id);
}
